import { defineStore } from "pinia";
import worthBuyApi from '@/api/worthBuy'
import type { navListData, topicsListData } from '@/api/worthBuy'

type WorthBuyStoreStateData = {
    navList1: navListData,
    navList2: navListData,
    ItemLeft: topicsListData,
    ItemRight: topicsListData
}

const useWorthBuyStore = defineStore('worthBuyStore', {
    state: (): WorthBuyStoreStateData => {
        return {
            navList1: [],
            navList2: [],
            ItemLeft: [],
            ItemRight:[]
        }
    },
    actions: {
        async getWorthBuyBannerList() {
            const res = await worthBuyApi.reqWorthBuyBannerList()
            const data = res.data.navList
            let num = Math.ceil(data.length / 2)
            let navList1 = data.slice(0, num)
            let navList2 = data.slice(num)
            this.navList1 = navList1
            this.navList2 = navList2
        },
        async getWorthBuyItemList() {
            const res = await worthBuyApi.reqWorthBuyItemList()
            this.ItemLeft = res.data.result[0].topics
            this.ItemRight = res.data.result[1].topics
            
            
        }
    },
    getters: {

    }
})
export default useWorthBuyStore